package com.yxw.live_vod_boot.service.impl;



import lombok.extern.slf4j.Slf4j;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import org.springframework.transaction.annotation.Transactional;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.hutool.core.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yxw.live_vod_boot.entity.YxLiveViolationEntity;
import com.yxw.live_vod_facade.dto.YxLiveViolationDTO;
import com.yxw.live_vod_boot.mapper.YxLiveViolationMapper;
import com.yxw.live_vod_boot.service.IYxLiveViolationService;
import com.yxw.live_vod_facade.dto.YxLiveViolationQueryDTO;


/*** 
*@author Jiaxu.Huang
*@date 2023/12/4 17:31:17
*@update 2023/12/4 17:31:17
**/
@Slf4j
@Service
//public class YxLiveViolationServiceImpl  extends ServiceImpl<YxLiveViolationMapper, YxLiveViolationEntity> implements IYxLiveViolationService{
public class YxLiveViolationServiceImpl  implements IYxLiveViolationService{
    @Autowired
    private YxLiveViolationMapper oYxLiveViolationMapper;
    /*** 
    * 保存
    * @param oYxLiveViolationDTO
    * @return BaseResult
    **/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public BaseResult insertYxLiveViolation(YxLiveViolationDTO oYxLiveViolationDTO)
    {
        oYxLiveViolationDTO.setId(null);
        YxLiveViolationEntity oYxLiveViolationEntity = new YxLiveViolationEntity();
        BeanUtil.copyProperties(oYxLiveViolationDTO, oYxLiveViolationEntity);
        oYxLiveViolationMapper.insert(oYxLiveViolationEntity);
        //oYxLiveViolationDTO.setViolationId(oYxLiveViolationEntity.getViolationId());
        return BaseResult.success(oYxLiveViolationEntity);
    }
    /*** 
    * 修改
    * @param oYxLiveViolationDTO
    * @return BaseResult
    **/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public BaseResult updateYxLiveViolationById(YxLiveViolationDTO oYxLiveViolationDTO)
    {
        YxLiveViolationEntity oYxLiveViolationEntity = new YxLiveViolationEntity();
        BeanUtil.copyProperties(oYxLiveViolationDTO, oYxLiveViolationEntity);
        oYxLiveViolationMapper.updateById(oYxLiveViolationEntity);
        return BaseResult.success();
    }
    /*** 
    * 删除
    * @param id
    * @return BaseResult
    **/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public BaseResult deleteYxLiveViolationById(Integer id)
    {
        if(ObjectUtil.isEmpty(id))
        {
            return BaseResult.failed("Id不能为空值");
        }
        oYxLiveViolationMapper.deleteById(id);
        return BaseResult.success();
    }
    /*** 
    * 根据id查找
    * @param id
    * @return YxLiveViolationEntity
    **/
    @Override
    public YxLiveViolationEntity selectYxLiveViolationById(Integer id)
    {
        if(ObjectUtil.isEmpty(id))
        {
            return null;
        }
        return oYxLiveViolationMapper.selectById(id);
    }
    /*** 
    * 自定义查询
    * @param oYxLiveViolationDTO
    * @return List<YxLiveViolationEntity>
    **/
    @Override
    public List<YxLiveViolationEntity> selectYxLiveViolationList(YxLiveViolationQueryDTO oYxLiveViolationDTO)
    {       
        QueryWrapper<YxLiveViolationEntity> oYxLiveViolationQueryWrapper = new QueryWrapper();
        oYxLiveViolationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getId()),"violation_id",oYxLiveViolationDTO.getId());
        oYxLiveViolationQueryWrapper.like(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getViolationReson()),"violation_reson","'%" + oYxLiveViolationDTO.getViolationReson()+ "%'");
        oYxLiveViolationQueryWrapper.like(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getViolationDescrption()),"violation_descrption","'%" +oYxLiveViolationDTO.getViolationDescrption() + "%'");
        oYxLiveViolationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getPunishType()),"punish_type",oYxLiveViolationDTO.getPunishType());
        oYxLiveViolationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getPunishQuantity()),"punish_quantity",oYxLiveViolationDTO.getPunishQuantity());
        oYxLiveViolationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getPunishUnit()),"punish_unit",oYxLiveViolationDTO.getPunishUnit());
        oYxLiveViolationQueryWrapper.ge(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getCreateStartTime()),"create_time",oYxLiveViolationDTO.getCreateStartTime());
        oYxLiveViolationQueryWrapper.le(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getCreateEndTime()),"create_time",oYxLiveViolationDTO.getCreateEndTime());
        //List<YxLiveViolationEntity> oListYxLiveViolation = oYxLiveViolationMapper.selectList(oYxLiveViolationQueryWrapper);
        //return Res.ok(oListYxLiveViolation);
        return  oYxLiveViolationMapper.selectList(oYxLiveViolationQueryWrapper);
    }
    /*** 
    * 自定义统计
    * @param oYxLiveViolationEntity
    * @return Integer
    **/
    @Override
    public Integer selectYxLiveViolationCount(YxLiveViolationQueryDTO oYxLiveViolationDTO)
    {
        YxLiveViolationEntity oYxLiveViolationEntity = new YxLiveViolationEntity();
        BeanUtil.copyProperties(oYxLiveViolationDTO, oYxLiveViolationEntity);
        QueryWrapper<YxLiveViolationEntity> oYxLiveViolationQueryWrapper = new QueryWrapper();
        oYxLiveViolationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getId()),"violation_id",oYxLiveViolationDTO.getId());
        oYxLiveViolationQueryWrapper.like(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getViolationReson()),"violation_reson","'%" + oYxLiveViolationDTO.getViolationReson()+ "%'");
        oYxLiveViolationQueryWrapper.like(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getViolationDescrption()),"violation_descrption","'%" +oYxLiveViolationDTO.getViolationDescrption() + "%'");
        oYxLiveViolationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getPunishType()),"punish_type",oYxLiveViolationDTO.getPunishType());
        oYxLiveViolationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getPunishQuantity()),"punish_quantity",oYxLiveViolationDTO.getPunishQuantity());
        oYxLiveViolationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getPunishUnit()),"punish_unit",oYxLiveViolationDTO.getPunishUnit());
        oYxLiveViolationQueryWrapper.ge(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getCreateStartTime()),"create_time",oYxLiveViolationDTO.getCreateStartTime());
        oYxLiveViolationQueryWrapper.le(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getCreateEndTime()),"create_time",oYxLiveViolationDTO.getCreateEndTime());
        return oYxLiveViolationMapper.selectCount(oYxLiveViolationQueryWrapper);
    }
    /*** 
    * 自定义分页查询
    * @param currentPage 当前页
    * @param pageSize 分页大小
    * @param oYxLiveViolationEntity
    * @return Page
    **/
    @Override
    public Page selectYxLiveViolationPage(YxLiveViolationQueryDTO oYxLiveViolationDTO)
    {
        Page<YxLiveViolationEntity> pageParams = new Page<>(oYxLiveViolationDTO.getCurrPage(),oYxLiveViolationDTO.getPageSize());
        QueryWrapper<YxLiveViolationEntity> oYxLiveViolationQueryWrapper = new QueryWrapper();
        oYxLiveViolationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getId()),"violation_id",oYxLiveViolationDTO.getId());
        oYxLiveViolationQueryWrapper.like(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getViolationReson()),"violation_reson","'%" + oYxLiveViolationDTO.getViolationReson() + "%'");
        oYxLiveViolationQueryWrapper.like(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getViolationDescrption()),"violation_descrption","'%" +oYxLiveViolationDTO.getViolationDescrption() + "%'");
        oYxLiveViolationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getPunishType()),"punish_type",oYxLiveViolationDTO.getPunishType());
        oYxLiveViolationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getPunishQuantity()),"punish_quantity",oYxLiveViolationDTO.getPunishQuantity());
        oYxLiveViolationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getPunishUnit()),"punish_unit",oYxLiveViolationDTO.getPunishUnit());
        oYxLiveViolationQueryWrapper.ge(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getCreateStartTime()),"create_time",oYxLiveViolationDTO.getCreateStartTime());
        oYxLiveViolationQueryWrapper.le(ObjectUtil.isNotEmpty(oYxLiveViolationDTO.getCreateEndTime()),"create_time",oYxLiveViolationDTO.getCreateEndTime());
        return oYxLiveViolationMapper.selectPage(pageParams, oYxLiveViolationQueryWrapper);
    }
}
    

